MaktoumZone = ZONE:New("MaktoumZone")
ZoneCaptureCoalition_Maktoum = ZONE_CAPTURE_COALITION:New(MaktoumZone,
SIDE.RED)

ZoneCaptureCoalition_Maktoum:__Guard(1)

ZoneCaptureCoalition_Maktoum:Start(1, 5)

-- zoneflag_Maktoum: 如果为true则代表之前是由蓝方占领的
local zoneflag_Maktoum = false

local airportname = "阿勒马克图姆"

local function clientsController(switch)
    CLIENTS_MAKTOUM:ForEachClient(function ( client )
        local name = client.ClientName
        USERFLAG:New(name):Set(switch)
    end)
end

-- 开始防卫区域
function ZoneCaptureCoalition_Maktoum:OnEnterGuarded( From, Event, To )
    
    if From ~= To then
        local coalition = self:GetCoalition()
        if coalition == SIDE.RED then
            MESSAGE:New("敌人占领了" .. airportname .. "机场!", 10, "格里芬战局通报", false):ToAll()

            SOUND_RADIOTRANS:ToAll()
            
            clientsController(100) -- 禁用机场客户端

            if RED_Base_Maktoum:GetFirstAliveGroup() == nil then
                RED_Base_Maktoum:Spawn()
            end -- 如果红方基地被摧毁了，则新建一个

            if RED_Maktoum_ATTK then
                RED_Maktoum_ATTK:SpawnScheduleStop()
            end -- 进攻Abu Dhabi的车队01

            zoneflag_Maktoum = false

        elseif coalition == SIDE.BLUE then
            MESSAGE:New("我们占领了" .. airportname .. "机场。请协助防御该机场。", 10, "格里芬战局通报", false):ToAll()
            STAGE:Set(3)
            clientsController(0)
            SOUND_AREASECURE:ToAll()
            
            zoneflag_Maktoum = true -- 更改阿勒马克图姆机场flag

            if BLUE_Base_Maktoum:GetFirstAliveGroup() == nil then -- 生成蓝方基地检查
                BLUE_Base_Maktoum:Spawn()
            end
            
            if RED_Maktoum_ATTK then
                RED_Maktoum_ATTK:SpawnScheduleStart()
            end -- 进攻Abu Dhabi的车队01

        end
    end
end

-- enter empty function
function ZoneCaptureCoalition_Maktoum:OnEnterEmpty()
    if zoneflag_Maktoum == false then -- 如果蓝方清空了机场

        MESSAGE:New("机场威胁已清除，地面部队正在接管" .. airportname .. "机场。", 10, "格里芬战局通报", false):ToAll()
        SOUND_JTFTRANS:ToAll()
        BLUE_Base_Maktoum:Spawn()
    else -- 如果红方清理了机场
        RED_Base_Maktoum:Spawn()
    end
end


function ZoneCaptureCoalition_Maktoum:OnEnterAttacked(From, Event, To)
    local coalition = self:GetCoalition()
    if coalition == SIDE.BLUE then
        MESSAGE:New(airportname .. "机场正在被敌方攻击！", 10, "格里芬战局通报", false):ToAll()
    else
        MESSAGE:New("我们正在攻击" .. airportname .. "机场！", 10, "格里芬战局通报", false):ToAll()
    end
    SOUND_JTFTRANS:ToAll()
end

